package cn.edu.sjtu.se.dslab.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.sjtu.se.dslab.auth.User;
import cn.edu.sjtu.se.dslab.dao.IUserDao;
import cn.edu.sjtu.se.dslab.service.IUserService;

@Service("userService")
@Transactional
public class UserServiceImpl implements IUserService {

	@Resource(name = "userDao")
	private IUserDao userDao;

	@Override
	public boolean addUser(User user) {
		userDao.save(user);
		return true;
	}

	@Override
	public User getUserById(long id) {
		// TODO Auto-generated method stub
		return userDao.queryById(id);
	}

	@Override
	public User updateUser(User user) {
		// TODO Auto-generated method stub
		userDao.update(user);
		return user;
	}

	/*
	 * getter and setter
	 */
	public IUserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(IUserDao userDao) {
		this.userDao = userDao;
	}

	@Override
	public User login(String username, String password) {
		return userDao.validUser(username, password);
	}

	@Override
	public List<User> searchUserPageBeanByProperty(String text) {
		// TODO Auto-generated method stub
		return userDao.queryByProperty(text);
	}

	@Override
	public User getUserByUsername(String username) {
		// TODO Auto-generated method stub
		return userDao.queryByUserName(username);
	}

}
